package br.com.caelum.vraptor.controller;

import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Timer;

import javax.inject.Inject;

import br.com.caelum.vraptor.Controller;
import br.com.caelum.vraptor.Result;
import br.com.caelum.vraptor.auth_annotations.Administrador;
import br.com.caelum.vraptor.auth_annotations.Professor;
import br.com.caelum.vraptor.dao.GenericDAO;
import br.com.caelum.vraptor.dao.LaboratorioDAO;
import br.com.caelum.vraptor.dao.ReservaDAO;
import br.com.caelum.vraptor.entidades.Reserva;

@Controller
public class ReservaController {
	

	@Inject
    private Result result;
 
    @Inject
    private GenericDAO<Reserva> dao;
    @Inject
    private LaboratorioDAO laboratorioDAO;
    
    public void add(){
           result.include("laboratorioList", laboratorioDAO.find()); 
    }
   
    public List<Reserva> list(){
            return dao.find();
    }
    
    public void save(Reserva reserva, Date hrfim, Date hrinicio){
    	
    	Date datainicio = new Date("datainicio:" + hrinicio);
    	Date datafim = new Date("datafim:" + hrfim);
    	
    	reserva.setHrinicio(hrinicio);
    	reserva.setHrfim(hrfim);
    	
    	dao.save(reserva);
        result.redirectTo(ReservaController.class).list();
 
    	
    }
   
    public Reserva edit(int id){
        return dao.find(id);
    }
   
    public void delete(int id){
    	Reserva reserva= new Reserva();
        reserva.setId(id);
        dao.delete(reserva);
        result.redirectTo(this).list();
    }
    
    public void error(){
    	
    }


}
